<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        #myCanvas {
            margin: 100px auto;
            display: block;
            border: 1px solid #ddd;
        }

        body {
            background-color: yellowgreen;
        }
    </style>
</head>
<body>
<canvas id="myCanvas" width="500" height="500"></canvas>
</body>


<script>
    let pi = Math.PI;
    let canvasEle = document.getElementById("myCanvas");
    let ctx = canvasEle.getContext("2d");

    let i = 0;

    
    function draw() {
        ctx.clearRect(0,0,500,500);
        ctx.save() ;

        ctx.translate(250, 250);
        ctx.rotate(pi * 0.1 + i);
        i+=10;
        ctx.strokeStyle = "red";
        ctx.strokeRect(-20, -50, 40, 100);
        ctx.restore();
    }

    let timer = setInterval(() => {
        draw();
    }, 100) 

</script>
</html>